package com.ykt.controller;

import com.jfinal.aop.Before;
import com.ykt.common.constant.ParamNames;
import com.ykt.common.utils.UB;
import com.ykt.converter.ShopCategoryConverter;
import com.ykt.model.ShopCategory;
import com.ykt.service.ShopCategoryService;
import com.ykt.validator.CommonValidator;
import com.ykt.vo.ResultVo;
import com.ykt.vo.ShopCategoryVo;

import java.util.List;

/**
 * 市场中商铺的分类
 * @author long.hua
 * @version 1.0.0
 * @since 2016-04-17 15:31
 */
public class ShopCategoryController extends BaseController{


    private ShopCategoryService categoryService = enhance(ShopCategoryService.class.getName(), ShopCategoryService.class);


    @Before(CommonValidator.MarketIdValidator.class)
    public void find() {
        int userId = UB.i(getPara(ParamNames.userId), 0);
        int marketId = UB.i(getPara(ParamNames.marketId), -1);
        int pid = UB.i(getPara(ParamNames.pid), 0);

        List<ShopCategory> shopCategories = categoryService.findByMarketId(marketId, pid);

        List<ShopCategoryVo> shopCategoryVos = ShopCategoryConverter.convert(shopCategories);

        this.returnJson(ResultVo.success(shopCategoryVos));
    }

}
